package com.ruoyi.web.controller.system;

import java.util.List;

import com.ruoyi.common.core.domain.entity.BcertInfo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.service.IBcertInfoService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 根证书Controller
 * 
 * @author ess
 * @date 2021-10-18
 */
@RestController
@RequestMapping("/system/bcertInfo")
public class BcertInfoController extends BaseController
{
    @Autowired
    private IBcertInfoService bcertInfoService;

    /**
     * 查询根证书列表
     */
    @PreAuthorize("@ss.hasPermi('system:bcertinfo:list')")
    @GetMapping("/list")
    public TableDataInfo list(BcertInfo bcertInfo)
    {
        startPage();
        List<BcertInfo> list = bcertInfoService.selectBcertInfoList(bcertInfo);
        return getDataTable(list);
    }

    /**
     * 导出根证书列表
     */
    @PreAuthorize("@ss.hasPermi('system:bcertinfo:export')")
    @Log(title = "根证书", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(BcertInfo bcertInfo)
    {
        List<BcertInfo> list = bcertInfoService.selectBcertInfoList(bcertInfo);
        ExcelUtil<BcertInfo> util = new ExcelUtil<BcertInfo>(BcertInfo.class);
        return util.exportExcel(list, "根证书数据");
    }

    /**
     * 获取根证书详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:bcertinfo:query')")
    @GetMapping(value = "/{bcertId}")
    public AjaxResult getInfo(@PathVariable("bcertId") String bcertId)
    {
        return AjaxResult.success(bcertInfoService.selectBcertInfoByBcertId(bcertId));
    }

    /**
     * 新增根证书
     */
    @PreAuthorize("@ss.hasPermi('system:bcertinfo:add')")
    @Log(title = "根证书", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BcertInfo bcertInfo)
    {
        return toAjax(bcertInfoService.insertBcertInfo(bcertInfo));
    }

    /**
     * 修改根证书
     */
    @PreAuthorize("@ss.hasPermi('system:bcertinfo:edit')")
    @Log(title = "根证书", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BcertInfo bcertInfo)
    {
        return toAjax(bcertInfoService.updateBcertInfo(bcertInfo));
    }

    /**
     * 删除根证书
     */
    @PreAuthorize("@ss.hasPermi('system:bcertinfo:remove')")
    @Log(title = "根证书", businessType = BusinessType.DELETE)
	@DeleteMapping("/{bcertIds}")
    public AjaxResult remove(@PathVariable String[] bcertIds)
    {
        return toAjax(bcertInfoService.deleteBcertInfoByBcertIds(bcertIds));
    }
}
